﻿
Namespace LightSwitchApplication

    Public Class InvoiceManagement

        Private Sub InvoiceManagement_InitializeDataWorkspace(saveChangesTo As System.Collections.Generic.List(Of Microsoft.LightSwitch.IDataService))
            ' Write your code here.
            Me.InvoiceHeaderProperty = New InvoiceHeader()

        End Sub

        Private Sub InvoiceManagement_Saved()
            ' Write your code here.
            Me.Close(False)
            Application.Current.ShowDefaultScreen(Me.InvoiceHeaderProperty)
        End Sub

        Private Sub CalculateInvoice_Validate(results As ScreenValidationResultsBuilder)
            ' results.AddPropertyError("<Error-Message>")
            Me.InvoiceHeaderProperty.InvoiceTotal = Me.SearchOrder.Sum(Function(expenditure) expenditure.NetAmount)
            Me.InvoiceHeaderProperty.Advance = Me.SearchOrder.Sum(Function(expenditure) expenditure.PaidAmount)
            ' Me.InvoiceHeaderProperty.PaidAmount = Me.SearchOrder.Sum(Function(expenditure) expenditure.TotalCharge)
            If Me.InvoiceHeaderProperty.Adjustment Is Nothing Then
                Me.InvoiceHeaderProperty.Adjustment = 0
            Else
                Me.InvoiceHeaderProperty.NetRemaining = 0
            End If
            Dim res = Me.InvoiceHeaderProperty.InvoiceTotal - (Me.InvoiceHeaderProperty.Advance + Me.InvoiceHeaderProperty.PaidAmount + Me.InvoiceHeaderProperty.Adjustment)
            If res IsNot Nothing Then
                Me.InvoiceHeaderProperty.NetRemaining = res
            Else
                Me.InvoiceHeaderProperty.NetRemaining = 0
            End If
        End Sub

        Private Sub CalculateInvoice_Changed()

        End Sub

        Private Sub SearchOrder_Validate(results As ScreenValidationResultsBuilder)
            ' results.AddPropertyError("<Error-Message>")

        End Sub

        Private Sub InvoiceHeaderProperty_Validate(results As ScreenValidationResultsBuilder)
            ' results.AddPropertyError("<Error-Message>")

        End Sub

        Private Sub InvoiceManagement_Created()
            ' Write your code here.
            Me.FindControl("CalculateInvoice").DisplayName = ""
            'Me.FindControl("CalculateInvoice").SetBinding(Button.ContentProperty, "Calculate Invoice")
        End Sub
    End Class

End Namespace